package com.aixin.project.handler;

import java.util.List;

import com.aixin.project.data.CommonConstants;
import com.aixin.project.data.User;
import com.aixin.project.db.UserDao;
import com.aixin.project.util.AxMemcached;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 12-4-14
 * Time: 上午2:23
 * To change this template use File | Settings | File Templates.
 */
public class UserHandler {
    public static User find(long uid){
    	User user = null;
    	Object obj = AxMemcached.get(CommonConstants.MKEY_USER + uid);
    	if(null == obj){
    		user = UserDao.find(uid);
            if(user!=null)
                AxMemcached.set(CommonConstants.MKEY_USER+uid,user);
        }
    	else
    		user = (User) obj;
        return user;
    }
    public static long insert(User user){
        return UserDao.insert(user);
    }
    public static List<User> getAllUsers(){
        return UserDao.queryAllUsers();
    }
    public static List<User> getAdminUsers(int page,int psize,int status){
    	return UserDao.listPagenation(page,psize,status);
    }
    public static User find(String username,String password){
    	return UserDao.find(username,password);
    }
    public static User find(String username){
    	return UserDao.find(username);
    }
    public static int update(User user){
    	return UserDao.update(user);
    	//AxMemcached.delete(CommonConstants.mk);
    }
    public static int update(String userid,String status){
    	return UserDao.update(userid,status);
    	//AxMemcached.delete(CommonConstants.mk);
    }
    public static int updatepwd(String userid,String pwd){
    	return UserDao.updatepwd(userid,pwd);
    	//AxMemcached.delete(CommonConstants.mk);
    }
    public static long find(){
    	return UserDao.queryAllUserscount();
    }
    public static long count(int status){
        return UserDao.count(status);
    }
}
